#pragma once
#include "View.h"

#include <list>
#include <memory>
#include "Size.h"
#include "CalcAnimation.h"

class EditObject;
class SkCanvas;
class SkFont;

//
//	TextView edit modes
//
#define MODE_READONLY	0
#define MODE_INSERT		1
#define MODE_OVERWRITE	2

class RichEditView :
	public View
{
public:
/*
	typedef struct
	{
		NMHDR	hdr;
		ULONG	nLineNo;
		ULONG	nColumnNo;
		ULONG	nOffset;
	} CURSORINFO;*/

	typedef struct
	{
		uint32	line;
		uint32	xpos;
	} CURPOS;

	RichEditView(View* parent);
	virtual ~RichEditView();
	virtual bool isLockFocus() { return true; }

	virtual void mouseEntry();
	virtual void mouseLeave();
	virtual void gotFocus();
	virtual void loseFocus();

	virtual void setText(std::wstring& text);

	virtual std::wstring getText();

	virtual void append(std::wstring& append_text);
	virtual void append(wchar_t append_text);

protected:
	virtual bool paint(SkCanvas* canvas);

	virtual bool paintBackground(SkCanvas* canvas);

	virtual bool paintFrontground(SkCanvas* canvas);

	virtual bool paintBorder(SkCanvas* canvas);

	virtual bool paintHover(SkCanvas* canvas);

	virtual bool paintFocus(SkCanvas* canvas);

	virtual bool paintCursorBlink(SkCanvas* canvas);
	// virtual bool processMouseEvent(MouseEvent& event);

	virtual bool processKeyEvent(KeyEvent& event);

/*
	gfx::Size calcTotalSize();
*/
private:
	struct EditLine
	{
		std::wstring str;
		int start_line;
	};

	std::list<std::shared_ptr<EditObject>> text_;
	HCURSOR cursor_;
	// std::shared_ptr<SkCanvas> canvas_;
	std::shared_ptr<SkFont> font_;
	int font_height_;
	CalcAnimation animation_;

	gfx::Size paint_size_;

	CURPOS cursor_pos_;
	int font_width_;
};

